package com.fuxin.hanfu.controller;

import com.fuxin.hanfu.domain.ItemOrder;
import com.fuxin.hanfu.service.ItemOrderService;
import com.fuxin.hanfu.uitls.MyResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/itemOrder")
public class ItemOrderController {
    @Resource
    private ItemOrderService itemOrderService;
    //查询
    @GetMapping("/find")
    public List<ItemOrder> findList(ItemOrder itemOrder){
        return itemOrderService.findList(itemOrder);
    }

    /*根据id查询*/
    @GetMapping("/find/{id}")
    public MyResponse findById(@PathVariable Integer id) {
        return MyResponse.toJson(true, itemOrderService.findById(id));
    }

    /*新增*/
    @PostMapping("/add")
    public Integer insert(@RequestBody ItemOrder itemOrder) {
        return itemOrderService.insert(itemOrder);
    }

    /*修改*/
    @PutMapping("/update")
    public MyResponse update(@RequestBody ItemOrder itemOrder) {
        return MyResponse.toJson(true, itemOrderService.update(itemOrder));
    }

    /*删除*/
    @DeleteMapping("/delete/{id}")
    public Integer delete(@PathVariable Integer id) {
        return  itemOrderService.delete(id);
    }

    /*发货*/
    @PutMapping("/ship/{id}")
    public MyResponse shipOrder(@PathVariable Integer id) {
        return MyResponse.toJson(true, itemOrderService.shipOrder(id));
    }
    /*收货*/
    @PutMapping("/receive/{id}")
    public MyResponse receiveOrder(@PathVariable Integer id) {
        return MyResponse.toJson(true, itemOrderService.receiveOrder(id));
    }
    /*付款*/
    @PutMapping("/pay/{id}")
    public MyResponse payOrder(@PathVariable Integer id) {
        return MyResponse.toJson(true, itemOrderService.payOrder(id));
    }
    /*取消订单*/
    @PutMapping("/cancel/{id}")
    public MyResponse cancelOrder(@PathVariable Integer id) {
        return MyResponse.toJson(true, itemOrderService.cancelOrder(id));
    }

    @GetMapping("/webFind")
    public List<ItemOrder> findOrdersByStatus(@RequestParam(value = "status", required = false) String status) {
        List<ItemOrder> orders = itemOrderService.findOrdersByStatus(status);
        return orders;
    }
}
